<template>
    <view class="page_gap page_news">
        <text class="h1" id="newsTitle">{{ newsData.sTitle }}</text>
        <view class="news_info">
            <text class="span" id="newsAuthor">{{ newsData.sFrom }}</text>
            <text class="span" id="newsDate">{{ newsData.time }}</text>
        </view>
        <view id="font-adjust">
            <view class="news_relative" id="newsRelative"></view>
            <view class="summary_block" id="summary">{{ newsData.sDescription }}</view>
            <view class="news_txt" id="newsContent">
                <!-- parse <template is="newsDetail" :data="...newsData"></template> -->
                <block name="newsDetail">
                    <block v-for="(cellData, idy) in content" :key="idy">
                        <view class="p" v-if="cellData.type == 'view'">
                            <block v-for="(item, index) in cellData.child" :key="item.text">
                                <text @tap="stockClick" class="a" :data-seccode="item.attr['data-seccode']" :data-secname="item.attr['data-secname']" v-if="item.type == 'a'">
                                    {{ item.text }}
                                </text>

                                <text v-else>{{ item.text }}</text>
                            </block>
                        </view>

                        <block v-if="cellData.type == 'img'">
                            {{ wn_html_images }}
                            <image
                                @load="imageLoad"
                                class="img"
                                :data-index="idy"
                                mode="widthFix"
                                :src="cellData.attr.src"
                                :style="'width: ' + cellData['attr']['width'] + ';max-width: 100%;height: ' + (cellData['attr']['height'] ? cellData['attr']['height'] : auto)"
                            ></image>
                        </block>
                    </block>
                </block>
            </view>
        </view>
    </view>
</template>

<script>
var app = getApp();
var R_htmlToWxml = require('../../resource/js/htmlToWxml.js');
export default {
    data() {
        return {
            scrollHeight: 0,

            newsData: {
                sTitle: '',
                sFrom: '',
                time: '',
                sDescription: ''
            },

            content: [],
            idy: '',

            cellData: {
                type: '',
                child: [],

                attr: {
                    src: ''
                }
            },

            auto: ''
        };
    },
    onLoad: function (e) {
        this.getNewsDetail();
        console.log('onLoad');
    },
    onShow: function () {
        console.log('onShow');
    },
    onReady: function () {
        console.log('onReady');
    },
    onHide: function () {
        console.log('onHide');
    },
    onUnload: function () {
        console.log('onUnload');
    },
    methods: {
        getNewsDetail: function () {
            var that = this;
            uni.request({
                url: 'https://wedengta.com/wxnews/getNews?action=DiscNewsContent&type=4&id=1478677877_1406730_1_9',
                headers: {
                    'Content-Type': 'application/json'
                },
                success: function (e) {
                    var o = e.data;
                    if (0 == o.ret) {
                        var n = JSON.parse(o.content);
                        n.content = R_htmlToWxml.html2json(n.sContent);
                        n.time = app.globalData.util.formatTime(1000 * n.iTime);
                        that.setData({
                            newsData: n
                        });
                    } else {
                        console.log('数据拉取失败');
                    }
                },
                fail: function (e) {
                    console.log('数据拉取失败');
                }
            });
        },

        stockClick: function (e) {
            var o = e.currentTarget.dataset.seccode;
            var n = e.currentTarget.dataset.secname;
            console.log('stockClick:' + o + ';secName:' + n);
        },

        imageLoad() {
            console.log('占位：函数 imageLoad 未声明');
        }
    }
};
</script>
<style>
@import './newsDetail.css';
</style>
